<template>
  <f7-page>
    <f7-navbar title="房间维护" back-link="Back">
      <f7-link slot="nav-right" href="/theroomadd/">
        <f7-icon material="add"></f7-icon>
      </f7-link>
    </f7-navbar>
    <f7-list v-for="(roomnumber, index) in object" :key="index">
      <f7-list-item swipeout :title="roomnumber.Number" :after="roomnumber.type">
        <f7-swipeout-actions right>
          <f7-swipeout-button delete confirm-text @click="delete1(roomnumber.id)">Delete</f7-swipeout-button>
        </f7-swipeout-actions>
      </f7-list-item>
    </f7-list>
  </f7-page>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      object: [],
      id: null
    };
  },
  mounted() {
    this.selectRoomNumber();
  },
  methods: {
    selectRoomNumber() {
      const self = this;
      const app = self.$f7;
      self.$f7.dialog.preloader("加载中");
      URL = "/caofuying/RoomNumber/selectRoomNumber";
      axios.get(URL, {}).then(r => {
        const { data } = r;
        if (data != null) {
          this.object = data;
          self.$f7.dialog.close();
        } else {
          app.dialog.alert("服务器错误");
        }
      });
    },
    delete1(id) {
      const self = this;
      const app = self.$f7;
      URL = `/caofuying/RoomNumber/deleteRoomNumber/${id}`;
      axios.delete(URL).then(r => {
        const { data } = r;
        if (data == 1) {
          app.dialog.alert("删除成功");
        } else if (data == 0) {
          app.dialog.alert("删除失败");
        } else {
          app.dialog.alert("服务器错误");
        }
      });
    }
  }
};
</script>